package com.xyz.practice.jdbc.databasemetadata;

import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.List;

public class DatabaseMetaDataAccess {

    private DatabaseMetaData dmd;

    public DatabaseMetaDataAccess( DatabaseMetaData dmd ) {
        this.dmd = dmd;
    }

    public Database getDatabase() throws SQLException {
        Database db = new Database();

        return db;
    }

    public List< ReferenceKey > getCrossReference( String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable ) throws SQLException {
        List< ReferenceKey > referenceKeys = Converter.convertReferenceKeys( dmd.getCrossReference( parentCatalog, parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable ) );
        return referenceKeys;
    }

    public List< ColumnPrivilege > getColumnPrivileges( String catalog, String schema, String table, String columnNamePattern ) throws SQLException {
        List< ColumnPrivilege > columnPrivileges = Converter.convertColumnPrivileges( dmd.getColumnPrivileges( catalog, schema, table, columnNamePattern ) );
        return columnPrivileges;
    }

    public List< ClientInfoProperty > getClientInfoProperties() throws SQLException {
        List< ClientInfoProperty > clientInfoPropertys = Converter.convertClientInfoProperties( dmd.getClientInfoProperties() );
        return clientInfoPropertys;
    }

    public List< ProcedureColumn > getProcedureColumns( String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern ) throws SQLException {
        List< ProcedureColumn > procedureColumns = Converter.convertProcedureColumns( dmd.getProcedureColumns( catalog, schemaPattern, procedureNamePattern, columnNamePattern ) );
        return procedureColumns;
    }

    public List< Procedure > getProcedures( String catalog, String schemaPattern, String procedureNamePattern ) throws SQLException {
        List< Procedure > procedures = Converter.convertProcedures( dmd.getProcedures( catalog, schemaPattern, procedureNamePattern ) );
        return procedures;
    }

    public List< ReferenceKey > getExportedKeys( String catalog, String schema, String table ) throws SQLException {
        List< ReferenceKey > referenceKeys = Converter.convertReferenceKeys( dmd.getExportedKeys( catalog, schema, table ) );
        return referenceKeys;
    }

    public List< ReferenceKey > getImportedKeys( String catalog, String schema, String table ) throws SQLException {
        List< ReferenceKey > referenceKeys = Converter.convertReferenceKeys( dmd.getImportedKeys( catalog, schema, table ) );
        return referenceKeys;
    }

    public List< FunctionColumn > getFunctionColumns( String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern ) throws SQLException {
        List< FunctionColumn > functionColumns = Converter.convertFunctionColumns( dmd.getFunctionColumns( catalog, schemaPattern, functionNamePattern, columnNamePattern ) );
        return functionColumns;
    }

    public List< Function > getFunctions( String catalog, String schemaPattern, String functionNamePattern ) throws SQLException {
        List< Function > functions = Converter.convertFunctions( dmd.getFunctions( catalog, schemaPattern, functionNamePattern ) );
        return functions;
    }

    public List< Attribute > getAttributes( String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern ) throws SQLException {
        List< Attribute > attributes = Converter.convertAttributes( dmd.getAttributes( catalog, schemaPattern, typeNamePattern, attributeNamePattern ) );
        return attributes;
    }

    public List< PrimaryKey > getPrimaryKeys( String table ) throws SQLException {
        return getPrimaryKeys( null, null, table );
    }

    public List< PrimaryKey > getPrimaryKeys( String catalog, String schema, String table ) throws SQLException {
        List< PrimaryKey > primaryKeys = Converter.convertPrimaryKeys( dmd.getPrimaryKeys( catalog, schema, table ) );
        return primaryKeys;
    }

    public List< Schema > getSchemas() throws SQLException {
        List< Schema > schemas = Converter.convertSchemas( dmd.getSchemas() );
        return schemas;
    }

    public List< Schema > getSchemas( String catalog, String schemaPattern ) throws SQLException {
        List< Schema > schemas = Converter.convertSchemas( dmd.getSchemas( catalog, schemaPattern ) );
        return schemas;
    }

    public List< Catalog > getCatalogs() throws SQLException {
        List< Catalog > catalogs = Converter.convertCatalogs( dmd.getCatalogs() );
        return catalogs;
    }

    public List< Column > getColumns( String tableNamePattern ) throws SQLException {
        return getColumns( null, null, tableNamePattern, null );
    }

    public List< Column > getColumns( String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern ) throws SQLException {
        List< Column > columns = Converter.convertColumns( dmd.getColumns( catalog, schemaPattern, tableNamePattern, columnNamePattern ) );
        return columns;
    }

    public List< TableType > getTableTypes() throws SQLException {
        List< TableType > tableTypes = Converter.convertTableTypes( dmd.getTableTypes() );
        return tableTypes;
    }

    public List< Table > getTables() throws SQLException {
        return getTables( null, null, null, null );
    }

    public List< Table > getTables( String catalog, String schemaPattern, String tableNamePattern, String[] types ) throws SQLException {
        List< Table > tables = Converter.convertTables( dmd.getTables( catalog, schemaPattern, tableNamePattern, types ) );
        return tables;
    }
}
